package com.lz.football.module.guide.view
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.GuideEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.events.NotifierEvent;
	import com.liangzhong.events.PlayerCenterEvent;
	import com.lz.football.module.guide.Guide;
	import com.lz.football.module.main.view.MainView;
	import com.lz.football.module.playerCenter.BattlearrayView;
	import com.lz.football.module.playerCenter.PlayerCenterListView;
	
	import flash.display.InteractiveObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import lz.controls.managers.AnimationManager;

	/**
	 *阵型设置 
	 * @author lake
	 * 
	 */	
	public class LineupSetGuideView extends Guide
	{
		public function LineupSetGuideView()
		{
			super();
		}
		/**
		 *初始化 
		 */		
		override protected function initView():void
		{
			super.initView();
			initDialog_1();
			//disable
			MainView.playerSearchBtn.mouseEnabled = false;
			MainView.bagBtn.mouseEnabled = false;
		}
		/**
		 * 场景内对话框 
		 *	球员中心
			官方说法：在这里可以查看拥有球员的信息和调整阵形！
			1L：有看着不顺眼的就把他解雇掉好了哟~
			2L：人手这么少哪舍得解雇哟~
			3L：卸磨杀驴的节奏哟~
		 * 
		 */		
		private function initDialog_1():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_7");
			GlobalDef.GameWindowContainer.addChild(bgMark);
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn1_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn1_Click(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn1_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			TweenLite.delayedCall(.2,getFuncIcon);
		}
		/**
		 *获得按钮
		 */		
		private function getFuncIcon():void
		{
			GlobalDef.GameWindowContainer.addChild(bgMark);
			sceneBtn = Reflection.createInstance("com.football.main.playerBtn");
			MainView.playerBtn.visible = false;
			
			var appearMc :MovieClip = Reflection.createInstance("com.football.guide.AppearAtSkin");
			DisplayObjectUtil.removeAllChildren(appearMc.mc.mc);
			appearMc.mc.mc.addChild(sceneBtn);
			sceneBtn.x = -16;
			sceneBtn.y = -14;
			(sceneBtn as InteractiveObject).mouseEnabled = false;
			addDispToStage(appearMc);
			var entP :Point = MainView.playerBtn.localToGlobal(new Point(0,0));
			AnimationManager.moveToThing(new Point(appearMc.x,appearMc.y),appearMc,entP,{delay:1,overwrite:0},.5);
			TweenLite.delayedCall(1.5,showFuncIcon);
		}
		/**
		 *显示按钮 
		 * 
		 */		
		private function showFuncIcon():void
		{
			MainView.playerBtn.visible = true;
			removeBgMark();
			//限制区域
			var rectPoint :Point = MainView.playerBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,MainView.playerBtn.width,MainView.playerBtn.height);
			step();
			//指向图标按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width/2,curClickRect.y);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,0);
			sceneBtn =  MainView.playerBtn;
			arrowAngle = 0;
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
		}
		/**
		 *界面显示
		 * @param e
		 * 
		 */		
		private function onLoadResComplete2(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			//限制区域
			var rectPoint :Point = PlayerCenterListView.battleBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,PlayerCenterListView.battleBtn.width,PlayerCenterListView.battleBtn.height);
			step();
			//指向阵型设置
			var arrrowPoint :Point = new Point(curClickRect.x,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn =  PlayerCenterListView.battleBtn;
			arrowAngle = -90;
			//事件
			GlobalDef.GameStage.addEventListener(PlayerCenterEvent.ADD_BATTLE_VIEW,showBattleView);
		}
		/**
		 *显示阵型设置面板 
		 * 
		 */		
		private function showBattleView(e:Event):void
		{
			GlobalDef.GameStage.removeEventListener(PlayerCenterEvent.ADD_BATTLE_VIEW,showBattleView);
			removeArrowMc();
			GlobalDef.GameWindowContainer.addChild(bgMark);
			initDialog_2();
			//enable
			MainView.playerSearchBtn.mouseEnabled = true;
			MainView.bagBtn.mouseEnabled = true;
		}
		/**
		 * 场景内对话框 
		 *	阵容设置
			官方说法：通过鼠标拖拽将球员替换上场。
			1L：灰色球员是最弱的！
			2L：一有机会就换掉灰色球员准没错！
			3L：灰>绿>蓝>紫>橙>红>黑
		 */		
		private function initDialog_2():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_8");
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn2_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn2_Click(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn2_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			GlobalDef.GameContainer.addChild(bgMark);
			removeMarkSp();
			BattlearrayView.SkinBg.mouseChildren = false;
			BattlearrayView.SkinBg.mouseEnabled = false;
			//限制区域
			var rectPoint :Point = BattlearrayView.SkinObj.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y + 75,BattlearrayView.SkinObj.width,BattlearrayView.SkinObj.height - 75);
			step();
			//保存区域
			rectPoint = BattlearrayView.saveBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,BattlearrayView.saveBtn.width,BattlearrayView.saveBtn.height);
			//指向保存
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  BattlearrayView.saveBtn;
			arrowAngle = 90;
			//事件
			AppEventDispatcher.getInstance().addEventListener(PlayerCenterEvent.SAVE_BATTLEARRAY,saveFormation);
		}
		/**
		 *舞台大小改变 
		 * @param e
		 * 
		 */		
		override protected function onResizeHandler(e :Event):void
		{
			if(sceneBtn != BattlearrayView.saveBtn)
			{
				super.onResizeHandler(e);
			}
			else
			{
				if(bgMark)
				{
					bgMark.width = GlobalDef.GameStage.stageWidth;
					bgMark.height = GlobalDef.GameStage.stageHeight;
				}
				if(_symbolSkin)
				{
					_symbolSkin.x = (GlobalDef.GameStage.stageWidth - _symbolSkin.width)/2;
					_symbolSkin.y = (GlobalDef.GameStage.stageHeight - _symbolSkin.height)/2;
				}
				//限制区域
				var rectPoint :Point = BattlearrayView.SkinObj.localToGlobal(new Point(0,0));
				curClickRect = new Rectangle(rectPoint.x,rectPoint.y + 75,BattlearrayView.SkinObj.width,BattlearrayView.SkinObj.height - 75);
				step();
				//保存区域
				rectPoint = BattlearrayView.saveBtn.localToGlobal(new Point(0,0));
				curClickRect = new Rectangle(rectPoint.x,rectPoint.y,BattlearrayView.saveBtn.width,BattlearrayView.saveBtn.height);
				//指向保存
				var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width,curClickRect.y + curClickRect.height/2);
				addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			}
		}
		/**
		 *保存阵容 
		 * @param e
		 * 
		 */		
		private function saveFormation(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(PlayerCenterEvent.SAVE_BATTLEARRAY,saveFormation);
			//提交引导
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE,{step:5}));
			//限制区域
			var rectPoint :Point = BattlearrayView.closeBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,BattlearrayView.closeBtn.width,BattlearrayView.closeBtn.height);
			step();
			//指向关闭按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width + 10,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  BattlearrayView.closeBtn;
			arrowAngle = 90;
			//事件
			GlobalDef.GameStage.addEventListener(PlayerCenterEvent.REMOVE_BATTLE_VIEW,onRemoveBattleHandler);
		}
		/**
		 *删除阵型设置面板 
		 * @param e
		 * 
		 */		
		private function onRemoveBattleHandler(e :Event):void
		{
			GlobalDef.GameStage.removeEventListener(PlayerCenterEvent.REMOVE_BATTLE_VIEW,onRemoveBattleHandler);
			//限制区域
			var rectPoint :Point = PlayerCenterListView.closeBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,PlayerCenterListView.closeBtn.width,PlayerCenterListView.closeBtn.height);
			step();
			//指向关闭按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width + 10,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  PlayerCenterListView.closeBtn;
			arrowAngle = 90;
			//事件
			AppEventDispatcher.getInstance().addEventListener(PlayerCenterEvent.REMOVE_MODEL,onRemoveModuleHandler);
		}
		/**
		 *  关闭
		 * @param e
		 * 
		 */		
		private function onRemoveModuleHandler(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(PlayerCenterEvent.REMOVE_MODEL,onRemoveModuleHandler);
			removeArrowMc();
			removeBgMark();
			removeMarkSp();
			//第5步刷新
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE+"_refresh",{step:5}));
		}
		/**
		 *执行 
		 * 
		 */		
		override public function process():void
		{
			initView();
		}
		/**
		 *清理 
		 * 
		 */		
		override public function clear():void
		{
			if(dialogBtn)
			{
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn1_Click);
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn2_Click);
			}
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			GlobalDef.GameStage.removeEventListener(PlayerCenterEvent.ADD_BATTLE_VIEW,showBattleView);
			AppEventDispatcher.getInstance().removeEventListener(PlayerCenterEvent.SAVE_BATTLEARRAY,saveFormation);
			GlobalDef.GameStage.removeEventListener(PlayerCenterEvent.REMOVE_BATTLE_VIEW,onRemoveBattleHandler);
			AppEventDispatcher.getInstance().removeEventListener(PlayerCenterEvent.REMOVE_MODEL,onRemoveModuleHandler);
			super.clear();
		}
	}
}